package com.elio.seatademoaccount.impl;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elio.seatademoaccount.AccountTblService;
import com.elio.seatademoaccount.mybatis.entity.AccountTbl;
import com.elio.seatademoaccount.mybatis.mapper.AccountTblMapper;
import lombok.var;
import org.springframework.stereotype.Service;

/**
* 账户
*/
@Service
public class AccountTblServiceImpl extends ServiceImpl<AccountTblMapper, AccountTbl>
implements AccountTblService {

    @Override
    public void debit(String userId, int money) {
        if(StringUtils.equals(userId, "2")) {
            throw new RuntimeException("模拟异常");
        }
        var wrapper = new LambdaUpdateWrapper<AccountTbl>();
        wrapper.setSql("money = money - " + money)
                .eq(AccountTbl::getUserId, userId);
        this.update(wrapper);
    }
}
